#pragma once
#include "stdafx.h"
#include "xercescHelpingLibrary.h"
#include "XMLElement.h"

namespace xercescHelpingLibrary
{
	class CXMLDocument
	{
		XercesDOMParser* m_parser;
		ErrorHandler* m_errHandler;
		DOMDocument* m_domDocument;
		CXMLElement* m_rootElement;
	private:
		CXMLDocument();
	public:
		~CXMLDocument();
	public:
		static CXMLDocument* OpenDocument(string xmlFilePath, string xsdFilePath);

		//static bool CreateDocument(string filePath, DOMNode* node)
		//{
		//	XMLCh tempStr[100];
		//	XMLString::transcode("LS", tempStr, 99);
		//	DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
		//	DOMLSSerializer* theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();

		//	// optionally you can set some features on this serializer
		//	if (theSerializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTDiscardDefaultContent, true))
		//		theSerializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTDiscardDefaultContent, true);

		//	if (theSerializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
		//		theSerializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);

		//	//// optionally you can implement your DOMLSSerializerFilter (e.g. MyDOMLSSerializerFilter)
		//	//// and set it to the serializer
		//	//DOMLSSerializer* myFilter = new myDOMLSSerializerFilter();
		//	//theSerializer->setFilter(myFilter);

		//	//// optionally you can implement your DOMErrorHandler (e.g. MyDOMErrorHandler)
		//	//// and set it to the serializer
		//	//DOMErrorHandler* errHandler = new myDOMErrorHandler();
		//	//theSerializer->getDomConfig()->setParameter(XMLUni::fgDOMErrorHandler, myErrorHandler);

		//	// StdOutFormatTarget prints the resultant XML stream
		//	// to stdout once it receives any thing from the serializer.
		//	//XMLFormatTarget *myFormTarget = new StdOutFormatTarget();
		//	XMLFormatTarget *myFormTarget = new LocalFileFormatTarget("TODO: ");


		//	DOMLSOutput* theOutput = ((DOMImplementationLS*)impl)->createLSOutput();
		//	theOutput->setByteStream(myFormTarget);

		//	try {
		//		// do the serialization through DOMLSSerializer::write();
		//		theSerializer->write(node, theOutput);
		//	}
		//	catch (const XMLException& toCatch) {
		//		char* message = XMLString::transcode(toCatch.getMessage());
		//		cout << "Exception message is: \n"
		//			<< message << "\n";
		//		XMLString::release(&message);
		//		return -1;
		//	}
		//	catch (const DOMException& toCatch) {
		//		char* message = XMLString::transcode(toCatch.msg);
		//		cout << "Exception message is: \n"
		//			<< message << "\n";
		//		XMLString::release(&message);
		//		return -1;
		//	}
		//	catch (...) {
		//		cout << "Unexpected Exception \n" ;
		//		return -1;
		//	}

		//	theOutput->release();
		//	theSerializer->release();
		//	//delete myErrorHandler;
		//	//delete myFilter;
		//	delete myFormTarget;
		//	return 0;
		//}

	public:
		CXMLElement* GetRootElement();
		CXMLElement* getElementByAttribute(string attributeName, string attributeValue);
	};

}